package tools;

import game.AbstractOthelloPosition;
import game.OthelloPosition;

public class Parser {
	
	/**
	 * Parse the argument string and create an Othello position
	 * @param position
	 * @return
	 */
	public static OthelloPosition parseArgs(String position) {
		if(position.length() != 65)
			return null;
		OthelloPosition game = new OthelloPosition();
		game.setPlayer(position.charAt(0) == 'W' ? true : false);
		char[][]  board = new char[AbstractOthelloPosition.BOARD_SIZE+2][AbstractOthelloPosition.BOARD_SIZE+2];
		char c;
		for (int i = 1; i <= AbstractOthelloPosition.BOARD_SIZE; i++) {
			for(int j = 1; j <= AbstractOthelloPosition.BOARD_SIZE; j++) {
				c = position.charAt((i - 1) * AbstractOthelloPosition.BOARD_SIZE + j);
				if(c == 'O')
					board[i][j] = 'W';
				else if(c == 'X')
					board[i][j] = 'B';
				else
					board[i][j] = c;
			}
		}
		game.setBoard(board);
		return game;
	}
}
